/**
 * 鸡蛋白JS
 * 编写人Wind
 */

  auto2();
  /*字体大小自适应rem单位*/
  function auto2(){
    var width = $('body').width();
    var font_size = 22*(width/320);
    var font_size2 = (width/320)*625+'%';
    $('body').css('font-size',font_size);
    $('html').css('font-size',font_size2);
  }

  /*浏览器横屏坚屏改变时也运行函数*/
  window.onorientationchange = function() {
    auto2();
  };

  /* 浏览器窗口发生改变也运行函数*/
  window.onresize=function(){
    auto2();
  };

  var get_poll = 1;
  /* 点击投票弹窗 */
  function poll(num){
    if (get_poll == 1) {
      get_poll = 0;
      var url = "glair.php?act=poll";
      $.post(url,{num :num},function(result){
      poll_return(result);
      },'json');
    }else{
      point('请勿重复投票');
    };
  }
  function poll_return(data){
      get_poll = 1;
      if(data.error>0){
      $(".full_screen,.ballot_popup,.reward_over").find('.message_1').html(data.message);
      $(".full_screen,.ballot_popup,.reward_over").show();
      $(".reward_begin").hide();
      }else{
      $(".full_screen,.ballot_popup,.reward_begin").show();
      $(".reward_over").hide();
      }
  }

  var get_glair = 1;
 /* 免费领取按钮方法 */
    function showPanic(){
        if (get_glair == 1) {
            get_glair = 0;
            $.getJSON('glair.php?act=get_glair',function(result){
                if (result.error == 8000) {
                    location.href = 'user.php';
                } else if (result.error == 8012) {
                    $('.panic-popup, .mask, .panic-popup .time-no').show();
                } else if (result.error == 8013) {
                    $('.panic-popup, .mask, .panic-popup .time-no').show();
                } else if (result.error == 8003) {
                    $('.panic-popup, .mask, .panic-popup .grab-no').show();
                } else if (result.error == 0) {
                    $('.panic-popup, .mask, .panic-popup .success').show();
                } else if (result.error == 8001) {
                    $('.panic-popup, .mask, .panic-popup .success2').show();
                }
                get_glair = 1;
            });
        }else{
            point('抢购中',1);
        };
    }

    // 点击分享改变内容
    $('.bdsharebuttonbox a').click(function(){
        $.getJSON('glair.php?act=get_glairBaoyou',function(result){
            if (result.error == 0) {
                $('.panic-popup .success').hide();
                $('.panic-popup .share-back').show();
            } else {
                $('.panic-popup .success').hide();
                $('.panic-popup .share-back2').show();
            }
        });
    });

  /* 点击空白区域把弹窗去掉 */
  $('.mask').click(function(){
    $(".mask,.panic-popup").hide();
  });

  /* 点击弹出微信窗口 */
  function weixin_popup(){
    $(".full_screen,.weixin_popup").show();
  }

  /* 点击弹出评论框 */
  function in_popup(){
    $(".in_one").hide();
    $(".in").show();
  }

  /* 鸡蛋白评论 */
  function glair_comment(){
    var comment = $('.comment .in .frame').val();
    if(comment == "" || comment == null){
      point('评论不能为空',1000);
      return false;
    }else{
      var url = "glair.php?act=comment";
      $.post(url,{comment :comment},function(data){
        if (data.error >0 ) {
           point(data.message,1000);
            return false;
        }else{
          point(data.message,1000);
          $('.comment .show').append(data.content);
        };
      },'json');
    }
  }

  /* 获取评论代码 */
  function getCommentHtml(img,username,content) {
    var html = '<div class="box">';
    html += '<img src="'+img+'.jpg" alt="头像">';
    html += '<span class="user_name">'+username+'</span><br />';
    html += '<p>'+content+'</p>';
    html += '</div>';
    return html;
  }

  /* 获取输入框焦点触发滚动至底部 */
  function scroll_bottom(){
    var scrollTop = $(this).scrollTop();
　　var scrollHeight = $(document).height();
　　var windowHeight = $(this).height();
    $('body,html').animate({scrollTop:scrollTop+(windowHeight/2)},500);
  }

  /* 点击领取滑动到获取区域 */
  function to_receive(){
    var scrollTop = document.getElementById("research").offsetTop-110;
    $('body,html').animate({scrollTop:scrollTop},800);
    // $('#notice_popup,.full_screen').show();
  }

  /* 判断页面是否活动到底部并加载更多评论 */
  $(window).scroll(function () {
    var scrollTop = $(this).scrollTop();
    var scrollHeight = $(document).height();
    var windowHeight = $(this).height();
    if (scrollTop + windowHeight == scrollHeight) {
      if($('.nim').hasClass("none")){
        var url = "glair.php?act=more_comment";
        var pages = $("#pages").val();
        $('.nim').removeClass('none');
        $.post(url,{pages :pages},function(result){
          more_comment_return(result);
        },'json');
      }
    }
  });

    function more_comment_return(data){
      if(data.error > 0){
        point(data.message,1);
        $('.nim').addClass('none');
        $(window).unbind();
      }
      else{
        $('.nim').addClass('none');
        $('#pages').before(data.content);
        var pages = parseInt($("#pages").val());
        $("#pages").val(pages+1);
      }
    }

    /* 调用轮播插件 */
    $(window).load(function() {
      $('.flexslider').flexslider({
        animation: "slide",
        controlNav: true,
        animationLoop: true,
        slideshow: true,
        slideshowSpeed: 3000,
      });
    });

    /* 点击如何获取领取码关闭按钮 */
    $('#notice_popup .close').click(function(){
      $('#notice_popup,.full_screen').hide();
    });

    // 百度分享
    window._bd_share_config = {
        common : {
            bdText : "bdText",
            bdDesc : "bdDesc",
            bdUrl : "bdUrl",
            bdPic : "bdPic"
        },
        share : [{
            "bdSize" : 16
        }],
    }

    with(document)[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];